Ubuntu 14.04
Sponsored Link

Use Basic Auth
2014/04/30
 
Enable Basic Authentication to limit access on specific web pages.
[1] For example, set Basic Authentication setting under the directory [/var/www/html/auth-basic].
root@www:~#
apt-get -y install apache2-utils
root@www:~#
vi /etc/apache2/sites-available/auth-basic.conf
# create new

<Directory /var/www/html/auth-basic>
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/apache2/.htpasswd
    require valid-user
</Directory>

# add a user : create a new file with "-c" ( add the "-c" option only for the initial registration )

root@www:~#
htpasswd -c /etc/apache2/.htpasswd trusty

New password:    
# set password

Re-type new password:
Adding password for user trusty
root@www:~#
mkdir /var/www/html/auth-basic

root@www:~#
a2ensite auth-basic

Enabling site auth-basic.
To activate the new configuration, you need to run:
  service apache2 reload

root@www:~#
/etc/init.d/apache2 restart

 * Restarting web server apache2
   ...done.

# create a test page

root@www:~#
vi /var/www/html/auth-basic/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for Basic Auth
</div>
</body>
</html>
[2] Access to the test page from a client computer with a web browser. Then authentication is required like follows as a setting, answer with a user added in [1].
[3] Just accessed.
 
Tweet